<?php

use yii\helpers\Html;
use kartik\widgets\ActiveForm;
use backend\models\Menu;
use kartik\widgets\Select2;

/* @var $this yii\web\View */
/* @var $model backend\models\Menu */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="menu-form">

    <?php
    $form = ActiveForm::begin([
                'options' => [
                    'class' => 'form-horizontal'
                ],
                'fieldConfig' => [
                    'template' => '{label}<div class="col-lg-7">{input}{hint}</div><div class="col-lg-3">{error}</div>',
                    'labelOptions' => ['class' => 'col-lg-2 control-label'],
                ]
    ]);
    ?>

    <?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>

    <?php
    echo $form->field($model, 'parent')->widget(Select2::className(), [
        'data' => Menu::getNode($type),
        'name' => 'parent',
        'options' => ['placeholder' => Yii::t('common', 'Select ...')],
    ]);
    ?>

    <?= $form->field($model, 'route')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'order')->textInput() ?>
    <?php
    echo $form->field($model, 'icon')->widget('zb\webuploader\FileInput', [
        'clientOptions' => [
            'pick' => [
                'multiple' => false,
            ]
        // 'server' => Url::to('upload/u2'),
        // 'accept' => [
        //     'extensions' => 'png',
        // ],
        ],
    ]);
    ?>
    <?= $form->field($model, 'data')->textArea(['rows' => 4]) ?>

<?php if (!Yii::$app->request->isAjax) { ?>
        <div class="form-group">
            <div class="col-lg-2"></div>
            <div class="col-lg-7"><?= Html::submitButton($model->isNewRecord ? Yii::t('common', 'Create') : Yii::t('common', 'Update'), ['class' => 'btn btn-primary']) ?></div>
        </div>
    <?php } ?>

<?php ActiveForm::end(); ?>

</div>
